package edu.guigu.appquickstart.adapterview;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.NonNull;

import edu.guigu.appquickstart.R;
import edu.guigu.appquickstart.adapterview.subitem.GridviewActivity;
import edu.guigu.appquickstart.adapterview.subitem.ListviewActivity;
import edu.guigu.appquickstart.adapterview.subitem.SpinnerActivity;
import edu.guigu.appquickstart.base.BaseActivity;

public class AdapterviewActivity extends BaseActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_adapterview);
        // ActionBar
        setSupportActionBar(findViewById(R.id.toolbar));
        getSupportActionBar().setTitle(R.string.title_activity_adapterview);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        // 按钮监听
        findViewById(R.id.btn_spanner).setOnClickListener(this);
        findViewById(R.id.btn_listview).setOnClickListener(this);
        findViewById(R.id.btn_gridview).setOnClickListener(this);
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if(item.getItemId() == android.R.id.home){
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        Intent intent = new Intent();
        if(id == R.id.btn_spanner){
            intent.setClass(this, SpinnerActivity.class);
            startActivity(intent);
        }
        if(id == R.id.btn_listview){
            intent.setClass(this, ListviewActivity.class);
            startActivity(intent);
        }
        if(id == R.id.btn_gridview){
            intent.setClass(this, GridviewActivity.class);
            startActivity(intent);
        }
    }
}